package com.lws.systembarsample

import android.os.Build
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat

class FullScreenNoInsetActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_no_inset)

        //设置decorView全屏显示,即显示区域延伸至状态栏、导航栏
        WindowCompat.setDecorFitsSystemWindows(window, false)



        setChangeSystemBarListener()
    }

    private fun setChangeSystemBarListener() {
        findViewById<Button>(R.id.lightStatusBar).setOnClickListener {
            ViewCompat.getWindowInsetsController(it)?.isAppearanceLightStatusBars = true

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                Toast.makeText(this, "安卓6.0 （api23） 以下 无效 ", Toast.LENGTH_LONG).show()
            }
        }

        findViewById<Button>(R.id.darkStatusBar).setOnClickListener {
            ViewCompat.getWindowInsetsController(it)?.isAppearanceLightStatusBars = false

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                Toast.makeText(this, "安卓6.0 （api23） 以下 无效 ", Toast.LENGTH_LONG).show()
            }
        }

        findViewById<Button>(R.id.lightNavBar).setOnClickListener {
            ViewCompat.getWindowInsetsController(it)?.isAppearanceLightNavigationBars = true

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
                Toast.makeText(this, "安卓8.0 （api26） 以下 无效 ", Toast.LENGTH_LONG).show()
            }
        }

        findViewById<Button>(R.id.darkNavBar).setOnClickListener {
            ViewCompat.getWindowInsetsController(it)?.isAppearanceLightNavigationBars = false

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                Toast.makeText(this, "安卓8.0 （api26） 以下 无效 ", Toast.LENGTH_LONG).show()
            }
        }
    }
}